package com.zhkj.txg.module.product.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.product.entity.*
import io.reactivex.disposables.Disposable

class ProductManager : BaseManager<ProductApi>(ProductApi::class.java) {

    /**
     * 获取首页数据
     */
    fun product(
        token: String,
        id: Int,
        shopId: Int = 0,
        listener: SubscribeListener<ProductResponse>
    ): Disposable {
        val homeData = apiService.product(token, id, shopId)
        return subscribe(homeData, ResponseSubscribeListener(listener))
    }

    /**
     * 获取首页数据
     */
    fun product2(
        token: String,
        id: Int,
        shopId: Int = 0,
        listener: SubscribeListener<ProductResponse2>
    ): Disposable {
        val homeData = apiService.product2(token, id, shopId)
        return subscribe(homeData, ResponseSubscribeListener(listener))
    }

    /**
     * 加入购物车
     */
    fun addCart(
        map: Map<String, String>, listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val addCart = apiService.addCart(map)
        return subscribe(addCart, ResponseSubscribeListener(listener))
    }

    /**
     * 收藏商品
     */
    fun collectProduct(
        token: String, shopId: Long, goodsId: Long, type: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val collectProduct = apiService.collectProduct(token, shopId, goodsId, type)
        return subscribe(collectProduct, ResponseSubscribeListener(listener))
    }

    /**
     * 排行榜商品
     */
    fun rankProduct(
        token: String, catId: Long, page: Int, rows: Int,
        listener: SubscribeListener<RankProductResponse>
    ): Disposable {
        val rankProduct = apiService.rankProduct(token, catId, page, rows)
        return subscribe(rankProduct, ResponseSubscribeListener(listener))
    }

    /**
     * 获取评论列表
     */
    fun commentList(
        goodsId: Long, type: Int, page: Int, rows: Int,
        listener: SubscribeListener<CommentListResponse>
    ): Disposable {
        val commentList = apiService.commentList(goodsId, type, page, rows)
        return subscribe(commentList, ResponseSubscribeListener(listener))
    }

    /**
     * 获取商品二维码
     */
    fun getQrCode(
        token: String, goodsId: Long,
        listener: SubscribeListener<CodeResponse>
    ): Disposable {
        val qrCode = apiService.getQRCode(token, goodsId)
        return subscribe(qrCode, ResponseSubscribeListener(listener))
    }
}